package com.example.controller;

import com.example.cac409club.response.RestResult;
import com.example.dto.IdentityDTO;
import com.example.entity.IdentityDO;
import com.example.service.IdentityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *   身份管理控制器
 * </p>
 * @author 34448
 */
@Api(tags = "身份管理")
@RequestMapping("/identity")
@RestController
public class IdentityController {

    @Autowired
    private IdentityService identityService;

    /**
     * 新增身份
     *
     * @param identityDTO 身份信息
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增身份")
    public RestResult<Boolean> addIdentity(@Valid @RequestBody IdentityDTO identityDTO) {
        Boolean result = identityService.addIdentity(identityDTO);
        return new RestResult<>("000000", "调用成功", result);
    }

    /**
     * 删除身份
     *
     * @param identityId 身份ID
     * @return
     */
    @DeleteMapping("/delete/{identityId}")
    @ApiOperation("删除身份")
    public RestResult<Boolean> deleteIdentity(@PathVariable Integer identityId) {
        Boolean result = identityService.deleteIdentity(identityId);
        return new RestResult<>("000000", "调用成功", result);
    }

    /**
     * 编辑身份
     *
     * @param identityDTO 身份信息
     * @return
     */
    @PutMapping("/edit")
    @ApiOperation("编辑身份")
    public RestResult<Boolean> editIdentity(@Valid @RequestBody IdentityDTO identityDTO) {
        Boolean result = identityService.editIdentity(identityDTO);
        return new RestResult<>("000000", "调用成功", result);
    }

    /**
     * 查询身份
     *
     * @param identityName 身份名称
     * @return
     */
    @GetMapping("/query")
    @ApiOperation("查询身份")
    public RestResult<List<IdentityDO>> queryIdentities(@RequestParam(required = false) String identityName) {
        List<IdentityDO> identities = identityService.queryIdentities(identityName);
        return new RestResult<>("000000", "调用成功", identities);
    }
}